/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * <p>Project: javaseapp - Img10
 * <p>Powered by webrx On 2021-08-16 11:02:02
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img12 {
    public static void main(String[] args) throws IOException {
        //原图
        String name = "images/o1.jpg";
        var src = ImageIO.read(new File(name));
        int sw = src.getWidth();
        int sh = src.getHeight();

        //缩略图尺寸(1) 指定尺寸
        int dw = 200;
        int dh = 280;

        //(2) 指定宽度，高度自动按比例计算
        dw = 200;
        dh = (int) (1.0 * dw / sw * sh);

        //(3) 直接绽放比例 1.5
        float s = 1.5f;
        dw = (int) (sw * s);
        dh = (int) (sh * s);

        int dt = BufferedImage.TYPE_INT_RGB;
        var dst = new BufferedImage(dw, dh, dt);
        var g = dst.createGraphics();

        g.drawImage(src, 0, 0, dw, dh, null);


        String dstname = String.format("%s%d×%d%s", name.substring(0, name.lastIndexOf(".")), dw, dh, name.substring(name.lastIndexOf(".")));
        System.out.println(name);
        System.out.println(dstname);
        ImageIO.write(dst, "jpg", new File(dstname));
    }

}
